VERSION 5.00
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Object = "{B3FB64BF-91F9-11D7-A482-0008A14158BC}#2.22#0"; "ITGControls.ocx"
Begin VB.Form frmAccountAffected 
   Caption         =   "Accounts Affected"
   ClientHeight    =   4650
   ClientLeft      =   -60
   ClientTop       =   225
   ClientWidth     =   7710
   Icon            =   "frmAccountAffected.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   4650
   ScaleWidth      =   7710
   StartUpPosition =   1  'CenterOwner
   Begin VB.Frame Frame2 
      Caption         =   "Account Details"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   3765
      Left            =   0
      TabIndex        =   6
      Top             =   840
      Width           =   7695
      Begin VB.CommandButton cmdAdd 
         Caption         =   "&Add"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   795
         Left            =   30
         Picture         =   "frmAccountAffected.frx":0CCA
         Style           =   1  'Graphical
         TabIndex        =   12
         Top             =   2940
         Width           =   1530
      End
      Begin VB.CommandButton cmdDelete 
         Caption         =   "&Delete"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   795
         Left            =   1560
         Picture         =   "frmAccountAffected.frx":1254
         Style           =   1  'Graphical
         TabIndex        =   11
         Top             =   2940
         Width           =   1530
      End
      Begin VB.CommandButton cmdGenerate 
         Caption         =   "&Generate"
         Enabled         =   0   'False
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   795
         Left            =   3090
         Picture         =   "frmAccountAffected.frx":17DE
         Style           =   1  'Graphical
         TabIndex        =   10
         Top             =   2940
         Width           =   1530
      End
      Begin VB.CommandButton cmdSave 
         Caption         =   "&Save"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   795
         Left            =   4620
         Picture         =   "frmAccountAffected.frx":1C20
         Style           =   1  'Graphical
         TabIndex        =   9
         Top             =   2940
         Width           =   1530
      End
      Begin VB.CommandButton cmdExit 
         Caption         =   "E&xit"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   795
         Left            =   6150
         Picture         =   "frmAccountAffected.frx":2196
         Style           =   1  'Graphical
         TabIndex        =   8
         Top             =   2940
         Width           =   1530
      End
      Begin MSDataGridLib.DataGrid grdDetails 
         Height          =   2745
         Left            =   0
         TabIndex        =   7
         Top             =   180
         Width           =   7680
         _ExtentX        =   13547
         _ExtentY        =   4842
         _Version        =   393216
         AllowUpdate     =   -1  'True
         AllowArrows     =   -1  'True
         Appearance      =   0
         HeadLines       =   1
         RowHeight       =   15
         TabAcrossSplits =   -1  'True
         TabAction       =   2
         FormatLocked    =   -1  'True
         AllowDelete     =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   8
         BeginProperty Column00 
            DataField       =   "cCompanyId"
            Caption         =   ""
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   "nIdentity"
            Caption         =   ""
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column02 
            DataField       =   "cTranNo"
            Caption         =   ""
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column03 
            DataField       =   "cAcctNo"
            Caption         =   "Account No."
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   "0%"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column04 
            DataField       =   "cTitle"
            Caption         =   "Title"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column05 
            DataField       =   "nDebit"
            Caption         =   "Debit"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column06 
            DataField       =   "nCredit"
            Caption         =   "Credit"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column07 
            DataField       =   "cCLRDNo"
            Caption         =   ""
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            BeginProperty Column00 
               Locked          =   -1  'True
               Object.Visible         =   0   'False
            EndProperty
            BeginProperty Column01 
               Locked          =   -1  'True
               Object.Visible         =   0   'False
            EndProperty
            BeginProperty Column02 
               Object.Visible         =   0   'False
            EndProperty
            BeginProperty Column03 
               Button          =   -1  'True
               ColumnWidth     =   1214.929
            EndProperty
            BeginProperty Column04 
               Locked          =   -1  'True
               ColumnWidth     =   2835.213
            EndProperty
            BeginProperty Column05 
               Alignment       =   1
               ColumnWidth     =   1425.26
            EndProperty
            BeginProperty Column06 
               Alignment       =   1
               ColumnWidth     =   1409.953
            EndProperty
            BeginProperty Column07 
               Object.Visible         =   0   'False
            EndProperty
         EndProperty
      End
   End
   Begin VB.Frame Frame1 
      Height          =   915
      Left            =   0
      TabIndex        =   0
      Top             =   -60
      Width           =   7695
      Begin ITGControls.ITGTextBox txtModule 
         Height          =   285
         Left            =   345
         TabIndex        =   1
         Top             =   225
         Width           =   2730
         _ExtentX        =   4604
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         AllCaps         =   -1  'True
         Mandatory       =   -1  'True
         Locked          =   -1  'True
         Label           =   "Module"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1320
         TextBoxWidth    =   1350
      End
      Begin ITGControls.ITGTextBox txtTranNo 
         Height          =   285
         Left            =   345
         TabIndex        =   2
         Top             =   525
         Width           =   2730
         _ExtentX        =   4604
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         AllCaps         =   -1  'True
         Mandatory       =   -1  'True
         Locked          =   -1  'True
         Label           =   "Trans. No."
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1320
         TextBoxWidth    =   1350
      End
      Begin ITGControls.ITGTextBox txtType 
         Height          =   285
         Left            =   4365
         TabIndex        =   3
         Top             =   225
         Width           =   2580
         _ExtentX        =   4339
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         AllCaps         =   -1  'True
         Mandatory       =   -1  'True
         Locked          =   -1  'True
         Label           =   "Type"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1320
         TextBoxWidth    =   1200
      End
      Begin ITGControls.ITGDateBox dtbDate 
         Height          =   285
         Left            =   5715
         TabIndex        =   4
         Tag             =   "Delivery Date"
         Top             =   525
         Width           =   1275
         _ExtentX        =   2249
         _ExtentY        =   503
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Text            =   ""
         SendKeysTab     =   -1  'True
         Mandatory       =   -1  'True
      End
      Begin ITGControls.ITGLabel ITGLabel4 
         Height          =   285
         Left            =   4395
         TabIndex        =   5
         Top             =   525
         Width           =   585
         _ExtentX        =   1032
         _ExtentY        =   503
         Caption         =   "Date"
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
      End
   End
End
Attribute VB_Name = "frmAccountAffected"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

'Reference type
Enum eModuleType
    KWRR
    KVOUCHER
    KCLEARING
    KAP
    KDR
    KSALES
    KAR
    KPR
    KDEPOSIT
    KBOUNCED
    KPAY
    KPULLED
    KREPLACEMENT
    KDEBIT
    KCREDIT
    KPI
    KEXPENSE
    KGL
End Enum

Public mModuleType As eModuleType
Public mRefPK As String

'Other declarations
Public dtgName As String

Private rsDetail As ADODB.Recordset

Private connList As New ADODB.Connection

Private Sub cmdExit_Click()
    Unload Me
End Sub

Private Sub cmdGenerate_Click()
On Error GoTo ErrorHandler
    
    Select Case mModuleType
        Case KWRR
            UpdateGLA "Update", "WRR", mRefPK
        Case KVOUCHER
            UpdateGLA "Update", "VOU", mRefPK
        Case KCLEARING
            UpdateGLA "Update", "CLR", mRefPK
        Case KAP
            UpdateGLA "Update", "AP", mRefPK
        Case KDR
            UpdateGLA "Update", "DR", mRefPK
        Case KSALES
            UpdateGLA "Update", "SI", mRefPK
        Case KAR
            UpdateGLA "Update", "AR", mRefPK
        Case KPR
            UpdateGLA "Update", "OR", mRefPK
        Case KDEPOSIT
            UpdateGLA "Update", "DP", mRefPK
        Case KBOUNCED
            UpdateGLA "Update", "RTC", mRefPK
        Case KDEBIT
            UpdateGLA "Update", "DBM", mRefPK
        Case KCREDIT
            UpdateGLA "Update", "CRM", mRefPK
        Case KPAY
            UpdateGLA "Update", "PAY", mRefPK
        Case KPI
            UpdateGLA "Update", "PI", mRefPK
        Case KEXPENSE
            UpdateGLA "Update", "SOE", mRefPK
        Case KGL
            UpdateGLA "Update", "GL", mRefPK
            
    End Select
    
    rsDetail.Requery
    If rsDetail.RecordCount = 0 Then
        cmdGenerate.Enabled = True
    Else
        cmdGenerate.Enabled = False
    End If
ErrorHandler:
'    If err.Number <> 0 Then
'        MsgBox err.Description, vbInformation, "ComUnion"
'    End If
End Sub

Private Sub Form_Load()
On Error GoTo ErrorHandler
Set rsDetail = New ADODB.Recordset
    Select Case mModuleType
        Case KWRR
            sSQL = "Select * from WRR where cWRRNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
            ListHeader
            sSQL = "Select * from GLActivity where cModule='WRR' and cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
        Case KVOUCHER
            sSQL = "Select * from VOUCHER where cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
            ListHeader
            sSQL = "Select * from GLActivity where cModule='VOU' and cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
        Case KCLEARING
            sSQL = "Select * from CLEARED where cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
            ListHeader
            sSQL = "Select * from GLActivity where cModule='CLR' and cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
        Case KAP
            sSQL = "Select * from AP where cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
            ListHeader
            sSQL = "Select * from GLActivity where cModule='AP' and cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
        Case KDR
            sSQL = "Select * from DR where cDRNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
            ListHeader
            sSQL = "Select * from GLActivity where cModule='DR' and cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
        Case KSALES
            sSQL = "Select * from SALES where cInvNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
            ListHeader
            sSQL = "Select * from GLActivity where cModule='SI' and cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
        Case KAR
            sSQL = "Select * from AR where cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
            ListHeader
            sSQL = "Select * from GLActivity where cModule='AR' and cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
        Case KPR
            sSQL = "Select * from PR where cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
            ListHeader
            sSQL = "Select * from GLActivity where cModule='OR' and cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "' order by nDebit desc"
        Case KDEPOSIT
            sSQL = "Select * from DEPOSIT where cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
            ListHeader
            sSQL = "Select * from GLActivity where cModule='DP' and cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
        Case KBOUNCED
            sSQL = "Select * from BOUNCED where cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
            ListHeader
            sSQL = "Select * from GLActivity where cModule='RTC' and cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
        Case KPULLED
            sSQL = "Select * from PULLED where cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
            ListHeader
            sSQL = "Select * from GLActivity where cModule='POC' and cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
        Case KDEBIT
            sSQL = "Select * from DEBIT where cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
            ListHeader
            sSQL = "Select * from GLActivity where cModule='DBM' and cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
        Case KCREDIT
            sSQL = "Select * from CREDIT where cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
            ListHeader
            sSQL = "Select * from GLActivity where cModule='CRM' and cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
        Case KPAY
            sSQL = "Select * from PAYABLES where cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
            ListHeader
            sSQL = "Select * from GLActivity where cModule='PAY' and cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
        Case KPI
            sSQL = "Select * from PURCHASE where cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
            ListHeader
            sSQL = "Select * from GLActivity where cModule='PI' and cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
        Case KEXPENSE
            sSQL = "Select * from PMS_EXPENSE where cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
            ListHeader
            sSQL = "Select * from GLActivity where cModule='SOE' and cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
        Case KGL
            sSQL = "Select * from GL where cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "'"
            ListHeader
            sSQL = "Select * from GLActivity where cModule='GL' and cTranNo='" & mRefPK & "' and cCompanyID = '" & Trim(COID) & "' order by nDebit desc"
            
        Case Others
    End Select
    
    OpenNewConnection connList
    rsDetail.Open sSQL, connList, adOpenForwardOnly, adLockBatchOptimistic
    Set grdDetails.DataSource = rsDetail
    grdDetails.Enabled = True
    If rsDetail.RecordCount = 0 Then cmdGenerate.Enabled = True
ErrorHandler:
    If err.Number <> 0 Then
'        MsgBox err.Description, vbInformation, "ComUnion"
   End If
   
End Sub

Private Sub Form_Unload(Cancel As Integer)
    RepName = ""
    cString = ""
    Set rsDetail = Nothing
    Set connList = Nothing
    Set frmAccountAffected = Nothing
End Sub

Sub ListHeader()
On Error GoTo ErrorHandler
    Set rs = New Recordset
    OpenNewConnection connList
    rs.Open sSQL, connList, adOpenForwardOnly, adLockReadOnly
    If rs.RecordCount = 0 Then
        Set rs = Nothing
        Exit Sub
    End If
    txtModule = RepName
    txtTranNo = mRefPK
    Select Case mModuleType
        Case KWRR
            txtType = rs!cType
            dtbDate.Text = Format(rs!dDate, "MM/dd/yyyy")
        Case KVOUCHER
            txtType = rs!cType
            dtbDate.Text = Format(rs!dDate, "MM/dd/yyyy")
        Case KCLEARING
            txtType = "CHECK"
            dtbDate.Text = Format(rs!dDate, "MM/dd/yyyy")
        Case KAP
            txtType = rs!cType
            dtbDate.Text = Format(rs!dDate, "MM/dd/yyyy")
        Case KDR
            txtType = rs!cType
            dtbDate.Text = Format(rs!dDate, "MM/dd/yyyy")
        Case KSALES
            txtType = rs!cType
            dtbDate.Text = Format(rs!dDate, "MM/dd/yyyy")
        Case KAR
            txtType = rs!cType
            dtbDate.Text = Format(rs!dDate, "MM/dd/yyyy")
        Case KPR
            txtType = "RECEIPT"
            dtbDate.Text = Format(rs!dDate, "MM/dd/yyyy")
        Case KDEPOSIT
            txtType = "DEPOSIT"
            dtbDate.Text = Format(rs!dDate, "MM/dd/yyyy")
        Case KBOUNCED
            txtType = "BOUNCED"
            dtbDate.Text = Format(rs!dDate, "MM/dd/yyyy")
        Case KPULLED
            txtType = "PULLED"
            dtbDate.Text = Format(rs!dDate, "MM/dd/yyyy")
        Case KDEBIT
            txtType = "DEBIT"
            dtbDate.Text = Format(rs!dDate, "MM/dd/yyyy")
        Case KCREDIT
            txtType = "CREDIT"
            dtbDate.Text = Format(rs!dDate, "MM/dd/yyyy")
        Case KPAY
            txtType = "PAY"
            dtbDate.Text = Format(rs!dDate, "MM/dd/yyyy")
        Case KPI
            txtType = "PURCHASE"
            dtbDate.Text = Format(rs!dDate, "MM/dd/yyyy")
        Case KEXPENSE
            txtType = "EXPENSE"
            dtbDate.Text = Format(rs!dDate, "MM/dd/yyyy")
        Case KGL
            txtType = "GL"
            dtbDate.Text = Format(rs!dDate, "MM/dd/yyyy")
    End Select
    dtbDate.Enabled = False
    Set rs = Nothing
ErrorHandler:
    If err.Number <> 0 Then
        'MsgBox err.Description, vbInformation, "ComUnion"
    End If
End Sub

Private Sub grdDetails_AfterColUpdate(ByVal ColIndex As Integer)
On Error GoTo ErrorHandler
'    If Mode <> AddNewEdit Then Exit Sub
    Select Case ColIndex
        Case 3
            If GetValueFrTable("cAcctNo", "ACCOUNT", "cAcctNo = '" & Trim(grdDetails.Columns(3).Text) & "'") <> "" Then
                grdDetails.Columns(4).Value = GetValueFrTable("cTitle", "ACCOUNT", "cAcctNo = '" & Trim(grdDetails.Columns(3).Text) & "'")
'                grdDetails.Columns(3).Value = rsDetail!cDesc
            End If
'        Case 4
'            If CDbl(grdDetails.Columns(4).Value) > 0 Then grdDetails.Columns(5).Value = 0
'            TotalAdjustmentAmount
'        Case 5
'            If CDbl(grdDetails.Columns(5).Value) > 0 Then grdDetails.Columns(4).Value = 0
'            TotalAdjustmentAmount
    End Select
ErrorHandler:
    If err.Number <> 0 Then
        MsgBox err.Description, vbInformation, "ComUnion"
    End If
End Sub

Private Sub grdDetails_ButtonClick(ByVal ColIndex As Integer)
On Error GoTo ErrorHandler
'    If Mode <> AddNewEdit Then Exit Sub
    Select Case ColIndex
        Case 3
            If lPickListActive Then Exit Sub
            sFilterString = Trim(grdDetails.Columns(3).Text)
            frmITGPicker.zType = QAccounts
            frmITGPicker.Show vbModal
            If Trim(frmITGPicker.zCode) = "" Then Exit Sub
            grdDetails.Columns(3).Value = frmITGPicker.zCode & ""
            grdDetails.Columns(4).Value = frmITGPicker.zName & ""
'            grdDetails.Col = 3
'            grdDetails.Columns(3).Value = rsDetail!cDesc
    End Select
ErrorHandler:
    If err.Number <> 0 Then
        MsgBox err.Description, vbInformation, "ComUnion"
    End If
End Sub

'Set the datagrid as active control
Private Sub grdDetails_Click()
'    If Mode = AddNewEdit Then dtgName = grdDetails.Name
End Sub

Private Sub grdDetails_Error(ByVal DataError As Integer, Response As Integer)
'    If Mode <> AddNewEdit Then
'        Response = 0
'        Exit Sub
'    End If
    If DataError = 7007 Then
        MsgBox "Type mismatch", vbExclamation, "ComUnion"
    ElseIf DataError = 13 Then
        MsgBox "Type mismatch", vbExclamation, "ComUnion"
    End If
    Response = 0
End Sub

Private Sub grdDetails_GotFocus()
    dtgName = grdDetails.Name
End Sub

Private Sub grdDetails_KeyDown(KeyCode As Integer, Shift As Integer)
'    If Mode <> AddNewEdit Then Exit Sub
    If (Shift = vbCtrlMask And KeyCode = 45) Then
        cmdAdd_Click
    ElseIf (Shift = vbCtrlMask And KeyCode = 46) Then
        cmdDelete_Click
    ElseIf (Shift = vbCtrlMask And KeyCode = 83) Then
'        TBSave
    End If
End Sub

Private Sub grdDetails_KeyPress(KeyAscii As Integer)
'    If Mode <> AddNewEdit Then Exit Sub
    If rsDetail.RecordCount = 0 Then Exit Sub

    If KeyAscii = 39 Then KeyAscii = 0 'Apostrophe {'}

    If KeyAscii = 13 Then
        Select Case grdDetails.Col
            Case 3
                If GetValueFrTable("cAcctNo", "ACCOUNT", "cAcctNo = '" & Trim(grdDetails.Columns(3).Text) & "'") = "" Then
                    grdDetails_ButtonClick (3)
                    Exit Sub
                End If
                SendKeys "{Tab}"
                SendKeys "{Tab}"
            Case Else
                SendKeys "{Tab}"
        End Select
    Else
        KeyAscii = Asc(UCase(Chr(KeyAscii)))
    End If

End Sub

'Right click menu popup
Private Sub grdDetails_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'    If Mode <> AddNewEdit Then Exit Sub
    If Button = 2 Then
        dtgName = grdDetails.Name
        PopupMenu ITGLedgerMain.mnuDetail
    End If
End Sub

Private Sub cmdAdd_Click()
On Error GoTo ErrorHandler
    rsDetail.AddNew
    rsDetail!cCompanyID = COID
    If mModuleType = KSALES Then
        rsDetail!cModule = "SI"
    Else
        rsDetail!cModule = txtModule.Text
    End If
    rsDetail!cTranNo = txtTranNo.Text
    rsDetail!dDate = dtbDate.Text
    rsDetail!lInternal = 0
    rsDetail!lExternal = 0
    rsDetail!cInterface = "NO INTERFACE"
    grdDetails.Col = 3
    grdDetails.SetFocus
ErrorHandler:
    If err.Number <> 0 Then
        MsgBox err.Description, vbInformation, "ComUnion"
    End If
End Sub

Private Sub cmdDelete_Click()
On Error GoTo ErrorHandler
    If rsDetail.RecordCount = 0 Then Exit Sub
    rsDetail.Delete adAffectCurrent
ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If
End Sub

Private Sub cmdSave_Click()
On Error GoTo ErrorHandler
    If rsDetail.RecordCount = 0 Then Exit Sub
    
        
    If ComputeTotal Then
        rsDetail.MoveFirst
        Do While Not rsDetail.EOF
                If IsNull(rsDetail!cAcctNo) Or rsDetail!cAcctNo = "" Then
                    rsDetail.Delete
                End If
                rsDetail.MoveNext
        Loop
        rsDetail.MoveFirst
        rsDetail.UpdateBatch adAffectAll
        MsgBox "Successfully Saves!", vbExclamation
    Else
        MsgBox "Unbalanced Transaction!", vbExclamation
    End If
ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If
End Sub

Function ComputeTotal()
Dim nDebit, nCredit As Double
    nDebit = 0
    nCredit = 0
    
    Set rs = New Recordset
    Set rs = rsDetail.Clone

    rs.MoveFirst
    Do Until rs.EOF
        nDebit = nDebit + IIf(IsNull(rs!nDebit), 0, rs!nDebit)
        nCredit = nCredit + IIf(IsNull(rs!nCredit), 0, rs!nCredit)
        rs.MoveNext
    Loop
    Set rs = Nothing

    If nDebit <> nCredit Then
        ComputeTotal = False
    Else
        ComputeTotal = True
    End If
End Function
